import { $GET } from '@/utils/services';
import type { IOrganizingData, IOrganizingType, ISchollsListRes } from './index.d';

// 获取班级树
export const getOrganizingClassTree = () => $GET<IOrganizingData[]>('/sys/corp/organize/classTree')

// 获取年级树
export const getOrganizingGradeTree = () => $GET<IOrganizingData[]>('/sys/corp/organize/gradeTree')

// 获取教职工部门树
export const getOrganizeDeptTree = () => $GET<IOrganizingData[]>('/sys/corp/organize/deptTree')

// 获取全部学校
export const getOrganizeSchools = async () => {
  let { code, data, msg } = await $GET<ISchollsListRes[]>('/sys/corp/organize/schools');
  let res = {
    code,
    data: data.map(item => {
      return {
        id: item.id,
        label: item.name,
        attribute: {
          nodeType: 'school'
        } 
      }
    }),
    msg
  }
  return Promise.resolve(res)
}

// 通过type获取不同的 组织机构树
export const getOrganizingByType = (type: IOrganizingType) => {
  switch (type) {
    case 'grade':
      return getOrganizingGradeTree();
    case 'dept':
      return getOrganizeDeptTree();
    case 'school':
      return getOrganizeSchools()
    default: return getOrganizingClassTree();
  }
}
